package com.saint.tvtest.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.saint.tvtest.bean.CatContent;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/27.
 */


public class CatPagerAdapter extends PagerAdapter {
    private List<View> list;


    public CatPagerAdapter(Context context, List<CatContent.DataBean> dataBeans) {
//        this.list = list;
        list = new ArrayList<>();
        for (int i = 0; i < dataBeans.size(); i++) {
            ImageView imageView = new ImageView(context);
            Glide.with(context).load(dataBeans.get(i).getUrl()).into(imageView);
            list.add(imageView);
        }

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = list.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(list.get(position));
    }
}
